<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui"
	xmlns:oso="http://osoftware.com/facelets"
	template="/WEB-INF/templates/mainEditLayout.xhtml">
	
	<ui:define name="title">
			#{resourceBundle['specialist.title']}
	</ui:define>
	
	<ui:define name="editFields">
		<p:wizard widgetVar="specialistWizard" flowListener="#{specialistController.onFlowProcess}" id="wizardView" backLabel="#{resourceBundle['wizard.back']}" nextLabel="#{resourceBundle['wizard.next']}">
			<p:tab id="tab1" title="1. Datos Personales">  
				<p:panelGrid columns="3">
					<oso:inputText id="firstName" label="#{resourceBundle['specialist.firstName']}"
						value="#{specialistModel.firstName}" required="true"/>
						
					<oso:inputText id="lastName" label="#{resourceBundle['specialist.lastName']}"
						value="#{specialistModel.lastName}"  required="true"/>
						
					<oso:calendar id="birthDate" label="#{resourceBundle['specialist.birthDate']}"
						value="#{specialistModel.birthDate}"  required="true"/>
						
					<oso:selectOneMenu id="documentType" 
						label="#{resourceBundle['specialist.documentType']}"
						value="#{specialistModel.documentType}" 
						converter="documentTypeConverter"
						items="#{specialistModel.selectableDocumentTypes}" 
						required="true"/>
						
					<oso:inputText id="documentNumber" label="#{resourceBundle['specialist.documentNumber']}"
						value="#{specialistModel.documentNumber}"  required="true"/>
				</p:panelGrid>
			</p:tab>
			<p:tab id="tab2" title="2. Domicilio"> 
				<p:panelGrid columns="3">
					<oso:inputText id="street" label="#{resourceBundle['specialist.street']}"
						value="#{specialistModel.address.street}"/>
						
					<oso:inputText id="number" label="#{resourceBundle['specialist.number']}"
						value="#{specialistModel.address.number}"/>
						
					<oso:inputText id="floor" label="#{resourceBundle['specialist.floor']}"
						value="#{specialistModel.address.floor}"/>
						
					<oso:inputText id="department" label="#{resourceBundle['specialist.department']}"
						value="#{specialistModel.address.department}"/>
						
					<oso:selectOneMenu id="city" 
						label="#{resourceBundle['specialist.city']}"
						value="#{specialistModel.address.city}" 
						converter="cityConverter"
						items="#{specialistModel.selectableCities}" 
						itemLabel="name"/>				
				</p:panelGrid>
			</p:tab>
			<p:tab id="tab3" title="3. Telefonos"> 
				<p:commandButton id="addPhone" value="Nuevo" oncomplete="phoneDialog.show();"  process="@this"
				actionListener="#{specialistController.addPhoneEvent}" update=":phoneDialogForm:phoneDialog">
				</p:commandButton>
				<p:dataTable id="listTable" var="row" value="#{specialistModel.editedEntity.phones}"
						paginator="true" 
						paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
						rowsPerPageTemplate="5,10,15"
						emptyMessage="#{resourceBundle['list.noData']}"
						paginatorAlwaysVisible="false">
						<p:column sortBy="#{row.countryCode}">
							<f:facet name="header">
								<h:outputText value="#{resourceBundle['phone.countryCode']}" />
							</f:facet>
							<h:outputText value="#{row.countryCode}" />
						</p:column>		
						<p:column sortBy="#{row.areaCode}">
							<f:facet name="header">
								<h:outputText value="#{resourceBundle['phone.areaCode']}" />
							</f:facet>
							<h:outputText value="#{row.areaCode}" />
						</p:column>		
						<p:column sortBy="#{row.phoneNumber}">
							<f:facet name="header">
								<h:outputText value="#{resourceBundle['phone.phoneNumber']}" />
							</f:facet>
							<h:outputText value="#{row.phoneNumber}" />
						</p:column>				
						<p:column>
							<ui:insert name="actionColumns"/>
							<p:commandLink title="#{resourceBundle['list.header.edit']}" oncomplete="phoneDialog.show();"
							process="@this" update=":phoneDialogForm:phoneDialog">
								<h:graphicImage value="/resources/images/edit.gif" />
								<f:setPropertyActionListener target="#{specialistModel.editedPhone}"
									value="#{row}" />
							</p:commandLink>
							<p:commandLink title="#{resourceBundle['list.header.delete']}" oncomplete="phoneConfirmation.show();"
							process="@this">
								<h:graphicImage value="/resources/images/delete.gif" />
								<f:setPropertyActionListener target="#{specialistModel.editedPhone}"
									value="#{row}" />
							</p:commandLink>
						</p:column>				
				</p:dataTable>
				
				<p:dialog id="confirmPhoneDialog"
				message="#{resourceBundle['popup.confirm']}"
				header="#{resourceBundle['popup.confirm']}" severity="alert"
				widgetVar="phoneConfirmation">
				
					<p:commandButton id="submitDeletePhoneButton" value="#{resourceBundle['btn.delete']}" 
                        actionListener="#{specialistController.confirmDeletePhoneEvent}" 
                        update="listTable" oncomplete="phoneConfirmation.hide();" process="@this"/>
                        
					<p:commandButton id="decline" value="#{resourceBundle['btn.cancel']}"
						onclick="phoneConfirmation.hide()" type="button" />
				</p:dialog>
			</p:tab>
			<p:tab id="tab4" title="4. Especialidad y Habilidades">  
				<p:panelGrid columns="3">
					<oso:inputText id="attentionTimeDuration" label="#{resourceBundle['specialist.attentionTimeDuration']}"
						value="#{specialistModel.attentionTimeDuration}" required="true"/>
						
					<oso:selectOneMenu id="speciality" 
						label="#{resourceBundle['specialist.speciality']}"
						value="#{specialistModel.speciality}" 
						converter="specialityConverter"
						items="#{specialistModel.selectableSpecialities}" 
						itemLabel="name"
						required="true"/>				
				</p:panelGrid>
			</p:tab>			
			<p:tab id="tab5" title="5. Tarifas"> 
				<p:commandButton id="addSpecialistFee" value="Nuevo" oncomplete="specialistFeeDialog.show();"  process="@this"
				actionListener="#{specialistController.addSpecialistFeeEvent}" update=":specialistFeeDialogForm:specialistFeeDialog">
				</p:commandButton>
				<p:dataTable id="listTableFees" var="row" value="#{specialistModel.editedEntity.fees}"
						paginator="true" 
						paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
						rowsPerPageTemplate="5,10,15"
						emptyMessage="#{resourceBundle['list.noData']}"
						paginatorAlwaysVisible="false">
						<p:column sortBy="#{row.description}">
							<f:facet name="header">
								<h:outputText value="#{resourceBundle['specialistFee.observation']}" />
							</f:facet>
							<h:outputText value="#{row.observation}" />
						</p:column>		
						<p:column sortBy="#{row.attentionType.name}">
							<f:facet name="header">
								<h:outputText value="#{resourceBundle['specialistFee.attentionType']}" />
							</f:facet>
							<h:outputText value="#{row.attentionType.name}" />
						</p:column>								
						<p:column sortBy="#{row.amount}">
							<f:facet name="header">
								<h:outputText value="#{resourceBundle['specialistFee.amount']}" />
							</f:facet>
							<h:outputText value="#{row.amount}" />
						</p:column>		
						<p:column>
							<ui:insert name="actionColumns"/>
							<p:commandLink title="#{resourceBundle['list.header.edit']}" oncomplete="specialistFeeDialog.show();"
							process="@this" update=":specialistFeeDialogForm:specialistFeeDialog">
								<h:graphicImage value="/resources/images/edit.gif" />
								<f:setPropertyActionListener target="#{specialistModel.editedSpecialistFee}"
									value="#{row}" />
							</p:commandLink>
							<p:commandLink title="#{resourceBundle['list.header.delete']}" oncomplete="specialistFeeConfirmation.show();"
							process="@this">
								<h:graphicImage value="/resources/images/delete.gif" />
								<f:setPropertyActionListener target="#{specialistModel.editedSpecialistFee}"
									value="#{row}" />
							</p:commandLink>
						</p:column>				
				</p:dataTable>
				
				<p:dialog id="confirmSpecialistFeeDialog"
				message="#{resourceBundle['popup.confirm']}"
				header="#{resourceBundle['popup.confirm']}" severity="alert"
				widgetVar="specialistFeeConfirmation">
				
					<p:commandButton id="submitDeleteSpecialistFeeButton" value="#{resourceBundle['btn.delete']}" 
                        actionListener="#{specialistController.confirmDeleteSpecialistFeeEvent}" 
                        update="listTableFees" oncomplete="specialistFeeConfirmation.hide();" process="@this"/>
                        
					<p:commandButton id="declineSpecialistFee" value="#{resourceBundle['btn.cancel']}"
						onclick="specialistFeeConfirmation.hide()" type="button" />
				</p:dialog>
			</p:tab>
		
		
		</p:wizard>
		
		<h:outputText value="" />
		<h:outputText value="" />
	</ui:define>
	
	<ui:define name="afterForm">
		<h:form id="phoneDialogForm">
				 <p:dialog widgetVar="phoneDialog" header="Detalle de Telefonos" showEffect="clip" hideEffect="clip" id="phoneDialog">
				 	<h:panelGrid columns="3">
				 		<oso:inputText id="countryCode" label="#{resourceBundle['phone.countryCode']}"
							value="#{specialistModel.editedPhone.countryCode}"/>
							
						<oso:inputText id="areaCode" label="#{resourceBundle['phone.areaCode']}"
							value="#{specialistModel.editedPhone.areaCode}"/>
							
						<oso:inputText id="phoneNumber" label="#{resourceBundle['phone.phoneNumber']}"
							value="#{specialistModel.editedPhone.phoneNumber}" required="true"/>
							
						<oso:inputText id="comment" label="#{resourceBundle['phone.comment']}"
							value="#{specialistModel.editedPhone.comment}"/>
							
                        <p:commandButton id="submitPhoneButton" value="#{resourceBundle['btn.save']}" 
                        action="phoneEvent"  oncomplete="handlePhoneServerResponse(xhr, status, args)"
                        update=":editForm:listTable"  process="phoneDialog" execute="@this"/>
                        <p:commandButton value="#{resourceBundle['btn.cancel']}" oncomplete="handlePhoneServerResponse(xhr, status, args)"/>
				 	</h:panelGrid>
				 </p:dialog>		
		</h:form>
		<script type="text/javascript">
	        function handlePhoneServerResponse(xhr, status, args) {
	            if (!args.validationFailed) {
	            	phoneDialog.hide();
	            }
	        }
	    </script>

		<h:form id="specialistFeeDialogForm">
				 <p:dialog widgetVar="specialistFeeDialog" header="Detalle de Telefonos" showEffect="clip" hideEffect="clip" id="specialistFeeDialog">
				 	<h:panelGrid columns="3">
				 		<oso:inputText id="observation" label="#{resourceBundle['specialistFee.observation']}"
							value="#{specialistModel.editedSpecialistFee.observation}"/>
							
						<oso:inputText id="amount" label="#{resourceBundle['specialistFee.amount']}"
							value="#{specialistModel.editedSpecialistFee.amount}"/>
							
						<oso:selectOneMenu id="attentionType" 
							label="#{resourceBundle['specialistFee.attentionType']}"
							value="#{specialistModel.editedSpecialistFee.attentionType}" 
							converter="attentionTypeConverter"
							items="#{specialistModel.selectableAttentionTypes}" 
							itemLabel="name"/>
						
						<oso:selectOneMenu id="attentionTypeMode" 
							label="#{resourceBundle['specialist.attentionTypeMode']}"
							value="#{specialistModel.editedSpecialistFee.attentionTypeMode}" 
							converter="attentionTypeModeConverter"
							items="#{specialistModel.selectableAttentionTypeModes}" 
							required="true"
							itemLabel="name"/>						
							
                        <p:commandButton id="submitSpecialistFeeButton" value="#{resourceBundle['btn.save']}" 
                        action="specialistFeeEvent" oncomplete="handleSpecialistFeeServerResponse(xhr, status, args)"
                        update=":editForm:listTableFees"  process="specialistFeeDialog" execute="@this"/>
                        <p:commandButton value="#{resourceBundle['btn.cancel']}" oncomplete="handleSpecialistFeeServerResponse(xhr, status, args)"/>
				 	</h:panelGrid>	
				 </p:dialog>		
		</h:form>
		<script type="text/javascript">
	        function handleSpecialistFeeServerResponse(xhr, status, args) {
	            if (!args.validationFailed) {
	            	specialistFeeDialog.hide();
	            }
	        }
	    </script>
	</ui:define>
	
</ui:composition>